package com.ctibook.booksystem.hibernatesearch.helper;

import java.io.IOException;

import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter;
import org.apache.lucene.util.OpenBitSet;

public class SubjectHeadingEmptyFilter extends Filter {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
		OpenBitSet obs=new OpenBitSet(reader.maxDoc());
		for(int i=0;i<reader.maxDoc();i++){
			Document document = reader.document(i);
			if(document!=null){
				String[] subjectHeadings = document.getValues("subjectHeadings.subjectHeading");
				String[] chineseSubjectHeadings=document.getValues("chineseSubjectHeadings.chineseSubjectHeading");
				if(subjectHeadings!=null&&subjectHeadings.length>0){
					if(chineseSubjectHeadings==null||chineseSubjectHeadings.length==0){
						obs.set(i);
					}
				}
			}
		}
		return obs;
	}

}
